package com.readaloud.wicket;


import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.PropertyModel;

import com.readaloud.hibernate.user.Books;
import com.readaloud.hibernate.user.GenreListBean;


public class BookClubPanel extends WebPage {
	
	private String genre; 
	public BookClubPanel(final GenreListBean genreListBean) {
		//super(id);
		/*if(pageParameters!=null){
			genre = pageParameters.get("genre").toString();
		}*/
		IModel bookModel = new LoadableDetachableModel() {
            protected Object load() {
                return WicketApplication.get().getInvertedIndexDao().getBooksbyGenre("abandon",genreListBean.getGenreName());
            }
        };
        setDefaultModel(bookModel);
        
        ListView bookClubList = new ListView("bookClubList", getDefaultModel()){
			@Override
			protected void populateItem(ListItem item) {
		        Books book = (Books) item.getModelObject();
				Link view = new Link("view", item.getModel()) {
                    public void onClick() {
                        setResponsePage(new ViewBook((Books)getModelObject()));
                    }
                };
                view.add(new Label("bookName", book.getName()));
                item.add(view);
			}
		};
        add(bookClubList);
	}

}
